package com.youi.web;

import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.youi.exception.BusinessException;
import com.youi.manage.HttpRequestManage;
import com.youi.common.DelStatus;
import com.youi.service.MerchantidtscService;
import com.youi.entity.Merchantgsp;
import com.youi.entity.Merchantidtsc;
import com.youi.common.Common;
import com.youi.util.CommonInfoUtil;
import com.youi.util.DateUtil;
import com.youi.util.JsonUtil;
import com.youi.util.ObjectUtil;
import com.youi.util.Page;

/**
* 互联网药品交易服务资格证书控制层
* @author Administrator
*/
@Controller
public class MerchantidtscController  extends HttpRequestManage{

		@Autowired
		private MerchantidtscService merchantidtscService;

		/**
		 * I-73
		 *添加或编辑互联网药品交易服务资格证书
		*/
		@ResponseBody
		@RequestMapping("sysUserGetInfo/addOrEditMerchantidtsc")
		public String addOrEditMerchantidtsc(ModelMap modelMap,HttpServletRequest request)throws BusinessException,ParseException{
			Long id=getLong("id",request);
			Map<String, Object> prams=new HashMap<String, Object>();
			prams.put(Common.DELSTATUS, DelStatus.NODEL);
			prams.put("merchantId", id);
			Merchantidtsc merchantidtsc=merchantidtscService.getByParam(prams);
			if (merchantidtsc==null) {
				merchantidtsc=new Merchantidtsc();
				merchantidtsc.setDelStatus(DelStatus.NODEL);
				merchantidtsc.setGmtCreated(new Date());
				merchantidtsc.setMerchantId(id);
			}
			String certNo=optString("certNo",request);
			if (certNo!=null){
				merchantidtsc.setCertNo(certNo);
			}
			String dns=optString("dns",request);
			if (dns!=null){
				merchantidtsc.setDns(dns);
			}
			String serviceScope=optString("serviceScope",request);
			if (serviceScope!=null){
				merchantidtsc.setServiceScope(serviceScope);
			}
			String certificate=optString("certificate",request);
			if (certificate!=null){
				merchantidtsc.setCertificate(certificate);
			}
			Date gmtValidity=optDate("gmtValidity", request, "yyyy-MM-dd HH:mm:ss");
			if (gmtValidity!=null) {
				merchantidtsc.setGmtValidity(gmtValidity);
			}
			merchantidtsc.setGmtModify(new Date());
			merchantidtscService.saveOrUpdate(merchantidtsc);
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成");
		}

	
		/**
		 * I-74
		 * 查询互联网药品交易服务资格证书
		*/
		@ResponseBody
		@RequestMapping("sysUserGetInfo/getMerchantidtscById")
		public String getMerchantidtscById(ModelMap modelMap,HttpServletRequest request) throws BusinessException{
			Long id=getLong("id",request);
			Map<String, Object> prams=new HashMap<String, Object>();
			prams.put(Common.DELSTATUS, DelStatus.NODEL);
			prams.put("merchantId", id);
			Merchantidtsc merchantidtsc=merchantidtscService.getByParam(prams);
			if (merchantidtsc==null) {
				return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "空数据");
			}
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成",merchantidtsc);//jsonObject	json对象
		}

}
